<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <div id="app">
    <btn-counter ref="btn1" @change="changeClick"></btn-counter>
    <btn-counter ref="btn2" @change="changeClick"></btn-counter>
    <div>
      总数: {{total}}
    </div>
  </div>

  <script src="./js/vue.js"></script>
  <script type="text/javascript">
    Vue.component("btn-counter", {
      data: function() {
        return {
        
        }
      },
      props: {
        couts: {
          default: 0,
          String: Number
        }
      },
      template: "<button @click='handclick'>{{couts}}</button>",
      methods: {
        handclick: function() {
          this.couts++;
          this.$emit('change', 1)
        }
      }
    })

    var app = new Vue({
      el: "#app",
      data:{
        total: 0
      },
      methods: {
        btnRes: function(){
          console.log(this.$refs.res);
        },
        changeClick(val) {
          this.total = this.$refs.btn1.couts + this.$refs.btn2.couts;
          console.log(this.$refs.btn1);
        }
      }
    })

  </script>
</body>
</html>